/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.hotel.test.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.hotel.test.model.Hotel;
import com.hotel.test.model.TblComment;
import com.hotel.test.service.HotelLocalServiceUtil;
import com.hotel.test.service.LocalLocalServiceUtil;
import com.hotel.test.service.base.HotelLocalServiceBaseImpl;
import com.hotel.test.service.persistence.HotelUtil;
import com.hotel.test.service.persistence.LocalUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the hotel local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.hotel.test.service.HotelLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Vien-IT
 * @see com.hotel.test.service.base.HotelLocalServiceBaseImpl
 * @see com.hotel.test.service.HotelLocalServiceUtil
 */
public class HotelLocalServiceImpl extends HotelLocalServiceBaseImpl {

	@Override
	public Hotel addHotel(Hotel hotel) throws SystemException {
		long hotelId = CounterLocalServiceUtil.increment();
		Hotel h = HotelUtil.create(hotelId);
		h.setHotelName(hotel.getHotelName());
		h.setIntroduce(hotel.getIntroduce());
		h.setQuality(hotel.getQuality());
		h.setLocalId(hotel.getLocalId());
		h.setImage(hotel.getImage());
		h.setAddress(hotel.getAddress());
		h.setEmail(hotel.getEmail());
		h.setPhone(hotel.getPhone());
		h.setCreateDate(new Date());
		h.setModifiedDate(new Date());
		h.setUserId(hotel.getUserId());
		
		return HotelUtil.update(h, false);
	}

	@Override
	public void deleteHotel(long hotelId) throws PortalException,
			SystemException {
		// TODO Auto-generated method stub
		super.deleteHotel(hotelId);
	}
	
	public List<Hotel> getAll() throws SystemException
	{
		
		return HotelUtil.findAll();
	}
	
	
	public List<Hotel> getByLocalId(long localId) throws SystemException
	{
		return LocalUtil.getHotels(localId);
				
	}
	
	public List<TblComment> getByHotelId(long hotelId) throws SystemException
	{
		return HotelUtil.getTblComments(hotelId);
	}
	
	public List<Hotel> getByQuality(int quality) throws SystemException
	{
		List<Hotel> hotels = HotelUtil.findAll();
		List<Hotel> news = new ArrayList<Hotel>();
		if(hotels == null)
			return null;
		else
		{
			for(Hotel h: hotels)
			{
				if(h.getQuality().equals(String.valueOf(quality)))
					news.add(h);
				
			}
			return news;
		}
	}
}